package org.films.domain;

import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.films.domain.Comment;

privileged aspect Consumer_Roo_Finder {
    
    public static Query Consumer.findConsumersByComments(Set<Comment> comments) {    
        if (comments == null) throw new IllegalArgumentException("The comments argument is required");        
        EntityManager em = Consumer.entityManager();        
        StringBuilder queryBuilder = new StringBuilder("SELECT Consumer FROM Consumer AS consumer WHERE");        
        for (int i = 0; i < comments.size(); i++) {        
            if (i > 0) queryBuilder.append(" AND");            
            queryBuilder.append(" :comments_item").append(i).append(" MEMBER OF consumer.comments");            
        }        
        Query q = em.createQuery(queryBuilder.toString());        
        int commentsIndex = 0;        
        for (Comment _comment: comments) {        
            q.setParameter("comments_item" + commentsIndex++, _comment);            
        }        
        return q;        
    }    
    
}
